package com.copa.l268;

import java.util.HashSet;
import java.util.Set;

/**
 * @author copa
 * @createDate 2022-06-01 18:05
 * @function HashSet法
 */
public class Test3 {

    public int missingNumber(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        for (int i = 0; i <= nums.length; i++) {
            if (!set.contains(i)) {
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] nums = {9,6,4,2,3,5,7,0,1};
        System.out.println(new Test3().missingNumber(nums));
    }
}
